//
//  LBMeUpdateAddrController.m
//  loveBeen
//
//  Created by lc on 2016/11/24.
//  Copyright © 2016年 loveBeen. All rights reserved.
//

#import "LBMeUpdateAddrController.h"
#import "LBMeUpdateAddrCell.h"
static NSString *ID1 = @"cell_id";
static NSString *ID2 = @"cellid";
@interface LBMeUpdateAddrController ()<LBMeUpdateAddrCellDelegate>

@end

@implementation LBMeUpdateAddrController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    
}

-(instancetype)initWithStyle:(UITableViewStyle)style {
    self = [super initWithStyle:style];
    if (self) {
        
    }
    
    return self;
}

-(void)setupUI{
    
    //设置title
    self.navigationItem.title = @"修改地址";
    
    //注册
    [self.tableView registerNib:[UINib nibWithNibName:@"LBMeUpdateAddrCell" bundle:nil]forCellReuseIdentifier:ID1];
    [self.tableView registerNib:[UINib nibWithNibName:@"LBMeUpdateAddrCellAdd" bundle:nil] forCellReuseIdentifier:ID2];
    
    //    self.tableView.estimatedRowHeight = 100;
    //    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
   // self.tableView.rowHeight = 250;

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
 
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LBMeUpdateAddrCell *cell;
    if (indexPath.row == 0 && indexPath.section == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:ID1 forIndexPath:indexPath];
        cell.model = _model;
    }else if(indexPath.row == 0 && indexPath.section == 1){
        cell = [tableView dequeueReusableCellWithIdentifier:ID2 forIndexPath:indexPath];
        cell.delegate = self;
    }
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 280;
    }else {
        return 40;
    }
}

//实现代理方法删除相关行联系人

-(void)deleteFromCell:(LBMeUpdateAddrCell *)cell {
    [self.navigationController popViewControllerAnimated:self];
    if ([_delegate respondsToSelector:@selector(deleteCurrentRow)]) {
        [_delegate deleteCurrentRow];
    }
}




/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
